using System;
using System.Globalization;
using System.Threading;
using System.Windows.Forms;
using QSBusinessLayerCSharp;
using ValidationFramework;

namespace QSWindowsApplicationCSharp
{
    public partial class MultiLanguageForm : Form
    {
        private readonly Registration registration;
        public MultiLanguageForm()
        {
            InitializeComponent();
            registration = new Registration();
        }

		private void MultiLanguageForm_Load(object sender, EventArgs e)
        {
            registrationBindingSource.Add(registration);
            cultureListBox.SelectedIndex = 0;
        }

        private void validateButton_Click(object sender, EventArgs e)
        {
            var manager = ValidationManagerFactory.GetPropertyValidationManager(registration);
            manager.ValidateAll();
            errorTreeView.Nodes.Clear();
            foreach (var result in manager.ValidatorResultsInError)
            {
                var node = new TreeNode(result.ErrorMessage);
                node.Nodes.Add(String.Format("RuleInterpretation = '{0}'", result.Rule.RuleInterpretation));
                node.Nodes.Add(String.Format("Rule = '{0}'", result.Rule.GetType()));
                errorTreeView.Nodes.Add(node);
            }
        }

        private void cultureListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo((string)cultureListBox.SelectedItem);
        }

    }
}